﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.ServiceModel.Dispatcher;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
namespace MessageLogWriter
{
    public class CustomMessageInspector : IDispatchMessageInspector
    {
        public object AfterReceiveRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel, System.ServiceModel.InstanceContext instanceContext)
        {
            Debug.WriteLine("AfterReceiveRequest:" + request.Properties.Via.AbsoluteUri);
            
            return "MyCustomToken";
        }

        public void BeforeSendReply(ref System.ServiceModel.Channels.Message reply, object correlationState)
        {
            if (correlationState is string && "MyCustomToken" == (string)correlationState)
            {
                Debug.WriteLine("BeforeSendReply Invoked ");
            }
        }
    }
}
